#ifndef _data_H_
#define _data_H_
#include "zf_common_headfile.h"

typedef struct {
    float kp;    //P
    float ki;    //I
    float kd;    //D

    float out_p;
    float out_i;
    float out_d;

    float error;
    float pre_error;
    float pre_pre_error;
} pid_param_t;

typedef struct
{
    enum {
        MODE_NORMAL, MODE_BANGBANG, MODE_SOFT, MODE_POSLOOP,
    } motor_mode;

    int64 total_encoder;
    int16 current_speed_raw;
    int16 current_speed;

    int16 target_speed;
    int32 duty;
} motor_param;

extern motor_param motor_l, motor_r;

extern pid_param_t motor_pid_l;
extern pid_param_t motor_pid_r;
extern pid_param_t servo_pid;

extern int protect_flag;

extern IfxCpu_mutexLock g_MutexUart;

extern int set_speed, set_speed_flash, circle_set_speed_flash, cross_set_speed_flash, bend_set_speed_flash, ramp_set_speed_flash;

extern float aim_distance_flash, circle_aim_distance_flash, cross_aim_distance_flash, bend_check_aim_distance, bend_aim_distance_flash, imu_aim_distance_flash, target_distance_mm;

extern float servo_duty;

void reset_all (void);

#define JOIN_OTHER_STATE (ramp_type == RAMP_NONE && circle_type == CIRCLE_NONE && cross_type == CROSS_NONE)

//#define HALF_ADJUST(left, right) ((left + right) / 2)

#define HALF_ADJUST(left, right) (right > left ? (left + right) / 2 : right)

#endif //_data_H_
